package com.gitee.feizns.explore.data_structure.recursive.linked;

/**
 * @author feizns
 * @since 2019/11/11
 */
public class ListNode {

    int val;

    ListNode next;

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int[] val) {
        if ( val.length > 0 ) {
            this.val = val[0];
            ListNode curt = this;
            for (int i = 1; i < val.length; i++) {
                curt.next = new ListNode(val[i]);
                curt = curt.next;
            }
        }
    }

    @Override
    public String toString() {
        StringBuilder ret = new StringBuilder();
        ListNode curt = this;
        while ( curt != null ) {
            ret.append(curt.val + " => ");
            curt = curt.next;
        }
        ret.append("NULL");
        return ret.toString();
    }

}
